<?php
include "../mysql.php";

$pageSize = $_REQUEST["rows"];
$pageNum = $_REQUEST["page"]; 
$nowPage=($pageNum-1)*$pageSize;

$sql_like='';
if($_REQUEST["prov"]){
  $prov=$_REQUEST["prov"].'%';
  $sql_like="WHERE `prov` like '$prov'";
}
if($_REQUEST["day"]&&$sql_like){
  $day=$_REQUEST["day"];
  $sql_like.=" AND `day`='$day'";
} else if($_REQUEST["day"]) {
  $day=$_REQUEST["day"];
  $sql_like="WHERE `day`='$day'";
}
$sql="SELECT * FROM `todayoil` ".$sql_like." ORDER BY `id` DESC LIMIT $nowPage,$pageSize";
$result = mysql_query($sql);  

$result1 = mysql_query("SELECT COUNT(*) FROM `todayoil`".$sql_like);
list($num_total) = mysql_fetch_row($result1);

if (!$result) {
  printf("Error: %s\n", mysql_query($con));
  exit();
}
$jarr = array();
while ($rows=mysql_fetch_array($result,MYSQL_ASSOC)){
    $count=count($rows);//不能在循环语句中，由于每次删除 row数组长度都减小  
    for($i=0;$i<$count;$i++){  
        unset($rows[$i]);//删除冗余数据  
    }
    array_push($jarr,$rows);
}
//print_r($jarr);//查看数组
//echo "<br/>";
//echo '<hr>';
$objdata=new stdclass();
$objdata->rows=(int)$pageSize;
$objdata->page=(int)$pageNum;
$objdata->total=(int)$num_total;
$objdata->rows=$jarr;

$jobj=new stdclass();//实例化stdclass，这是php内置的空类，可以用来传递数据，由于json_encode后的数据是以对象数组的形式存放的，
$jobj->success=true;
$jobj->data=$objdata;
//echo '传递属性后的对象：';
//print_r($jobj);//打印传递属性后的对象
//echo '<br>';
echo json_encode($jobj);//打印编码后的json字符串



mysql_close($con);//关闭数据库连接
?>